<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.io.*, java.sql.*, java.util.*,LS.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
if(request.getParameter("id")!=null){
	if(request.getParameter("password")!=null){
		String id = request.getParameter("id");
		String pw = request.getParameter("password");
		String url = "index.jsp";
		String errMsg = "";
		
		if(id == null){
			id = "";
			pw = "";
		}else{
			Users u = UsersHome.selectById(id);
			List<vwUDD> udd;
			if(vwUDDHome.departments_name(id).size() == 1){
				udd.add(vwUDDHome.departments_name(id).get(0));
			}else{
				udd.add(vwUDDHome.departments_name(id).get(0));
				udd.add(vwUDDHome.departments_name(id).get(1));
			}
			if(u==null){%>
				<script>
					window.alert("유저의 아이디가 존재하지 않습니다.");
					history.go(-1);
				</script>
			<% }else if(!pw.equals(u.getPassword())){%>
				<script>
				window.alert("패스워드가 틀립니다.");
				history.go(-1);
				</script>
			<% }else{
				session.setAttribute("user", u);
				session.setAttribute("userid", id);
				session.setAttribute("departments_id", udd.get(0));
				if(vwUDDHome.departments_name(id).size() == 2){
					session.setAttribute("departments_id2", udd.get(1));
				}
				%>
				
				<script>
					alert("잉");
<%-- 					alert("<%=udd.get(0)%>"); --%>
					alert("접속완료11111111");
					location.href= 'top.do';
				</script>
				<%
				return;
			}
		}
	}
}
%>